package com.local.web.controller;


import com.local.carousel.pojo.Carousel;
import com.local.goods.pojo.GoodsCategory;
import com.local.indexconfig.pojo.IndexConfig;
import com.local.web.constants.IndexConfigTypeEnum;
import com.local.web.constants.WebConstants;
import com.local.web.service.CarouselService;
import com.local.web.service.GoodsCategoryService;
import com.local.web.service.IndexConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class IndexController {

    @Autowired
    private GoodsCategoryService goodsCategoryService;

    @Autowired
    private CarouselService carouselService;

    @Autowired
    private IndexConfigService indexConfigService;


    @GetMapping({"", "/", "/index", "/index.html"})
    public String index(HttpServletRequest request) {
        //查询首页的分类列表
        List<GoodsCategory> indexCategoryList = goodsCategoryService.getIndexCategoryList();

        //轮播图片
        List<Carousel> carouselList = carouselService.getCarouselList();

        //首页的商品推荐
        List<IndexConfig> hotGoodsList = indexConfigService.getListByConfigType(IndexConfigTypeEnum.INDEX_GOODS_HOT.getType(), WebConstants.INDEX_GOODS_HOT_NUMBER);
        List<IndexConfig> newGoodsList = indexConfigService.getListByConfigType(IndexConfigTypeEnum.INDEX_GOODS_NEW.getType(), WebConstants.INDEX_GOODS_NEW_NUMBER);
        List<IndexConfig> recGoodsList = indexConfigService.getListByConfigType(IndexConfigTypeEnum.INDEX_GOODS_RECOMMOND.getType(), WebConstants.INDEX_GOODS_RECOMMEND_NUMBER);

        request.setAttribute("categoryList", indexCategoryList);
        request.setAttribute("carouselList", carouselList);
        request.setAttribute("hotGoodsList", hotGoodsList);
        request.setAttribute("newGoodsList", newGoodsList);
        request.setAttribute("recGoodsList", recGoodsList);

        return "mall/index";
    }
}
